package cn.edu.nju.askme.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Component;

import cn.edu.nju.askme.model.User;
import cn.edu.nju.askme.service.IUserService;

import com.opensymphony.xwork2.ActionSupport;
@Component
public class UserLoginAction extends ActionSupport implements SessionAware{
	private String loginName;
	private String password;
	private IUserService userService;
	private Map session;
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public IUserService getUserService() {
		return userService;
	}
	@Resource
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	public Map getSession() {
		return session;
	}
	public void setSession(Map session) {
		this.session = session;
	}
	@Override
	public String execute() throws Exception {
		User temp= userService.check(loginName);
		if(temp!=null&&temp.getPassword().equals(password)) {
			session.put("user", temp);
			System.out.println("UserLoginAction.execute()");
			return SUCCESS;
		}
		return ERROR;
	}
}
